Bike Trips Sample Application: Using the XMLConnector Component in Flash MX Professional 2004
Table of Contents
- Introduction
- Getting Started: Examining the Bike Trips Application and Its Data
- Configuring the Application to Use the XMLConnector Component
- Binding XML Data to a ComboBox Component
- Creating ComboBox Labels Using XML Data
- Displaying and Updating a Trip Description in a TextArea Component
- Displaying and Updating a Formatted Cost in a TextInput Component
- Displaying and Updating a Graphic in a Loader Component
- Summary and Related Articles and Resources
Displaying and Updating a Graphic in a Loader Component
- Save XMLConnector_step4.fla as XMLConnector_step5.fla.
- Open the Components panel, drag an instance of the Loader component onto the Stage, and drop it below the words "Bike Trip Central," and above the other components.
Open the Property inspector for this new Loader instance, and set the following values:
- Instance Name: loImage
- Width: 297
- Height: 85
- X: 2
Note: While you can set default contentPath for a Loader component, do not do so here because the xcTrips XMLConnector will provide this path dynamically, and users will specify changes to the path through their selections in the cbTrips ComboBox. Because you've set a default selectedIndex of 0 for the ComboBox, data will bind as the movie first loads and the image for the first ComboBox item (napa.jpg) will appear.
Expose the image property from trip:Array in xcTrips as an available binding:
- Select xcTrips.
- Open the Component Inspector panel and select the Bindings tab.
- Click the Plus (+) button to add a new data binding, exposing the imported XML data schema, which you previously bound to xcTrips.
- Select the image property in the array of trip objects (called trip:Array) from the schema and click OK.
- You should now see the results.trips.trip.[n].image property of xcTrips listed as a binding available from xcTrips.
Attach the newly exposed binding to the contentPath property of the loImage Loader component:
- Select the results.trips.trip.[n].image binding from the Bindings tab in the Component Inspector panel for the xcTrips XMLConnector.
- In the Bindings property grid, below the binding, set the direction property for this binding to "out."
- Select the bound to property, and press the magnifying glass button.
In the Bound To dialogue, set the following:
- Component Path: Loader <loImage>
- Schema Location: contentPath : String
- Select Control > Test Movie to test your application. Notice that the image for the first trip (napa.jpg) now appears in the loImage Loader component. However, if you select a different value in cbTrips, the image does not yet update.
-
Once again, use the selectedIndex property of the cbTrips ComboBox component to make the currently selected row trigger the correct image to display in the loImage Loader component. Do this by using the selectedIndex property to dynamically determine the correct image property from the array of trip objects in xcTrips to bind to the Loader component. Because data bindings dynamically update when bound values change, the image will update whenever the trip name changes:
- Select the xcTrips XMLConnector.
- Open the Component Inspector panel and select the Bindings tab.
- Select the results.trips.trip.[n].image binding.
- Select the Index for 'trip' property, and press the magnifying glass button.
In the Bound Index dialogue, uncheck "use a constant value" and set the following:
- Component Path: cbTrips ComboBox
- Schema Location: selectedIndex : Number
Note: Again, because you previously set a default value of zero for cbTrips' selectedIndex property, data binds when the application first loads, just as though a user had selected that index of the ComboBox. So, all data binding tied to cbTrips will occur on load, including this new binding to the Loader component.
- Select Control > Test Movie to test your application. You should see the trip "Napa," its description, its formatted cost, and the graphic napa.jpg as you load. As you change the trip name, the cost, description, and images should automatically update.
- Save your changes to XMLConnector_step5.fla.